<?php 
namespace app\Index\controller;

use think\Controller;
use think\Db;
use think\Request;

/**
 * 
 */
class Index extends Controller
{
	public function Index()
	{
		return view('add');
	}

	public function add_do()
	{
		$request=Request::instance();
		$data=$request->post();
		$res=Db::table('week3')->insert($data);
		if ($res) {
			$this->success('添加成功','show');
		}else{
			$this->error('添加失败');
		}
	}
	public function show()

	{
		$data=Db::table('week3')->select();
		return view('show',['data'=>$data]);
	}
	public function delete()
	{
		$request=Request::instance();
		$id=$request->get('id');
		$data=Db::table('week3')->where('id='.$id)->delete();
		if ($data) {
			$this->success('删除成功','show');
		}else{
			$this->error('删除失败');
		}
	}
	public function update()
	{
		$request=Request::instance();
		$id=$request->get('id');
		$data=Db::table('week3')->where('id='.$id)->find();
		return view('update',['data'=>$data]);
	}
	public function update_do()
	{
		$id=$_POST['id'];
		$request=Request::instance();
		$data=$request->post();
		$res=Db::table('week3')->where('id='.$id)->update($data);
		if ($res) {
			$this->success('修改成功','show');
		}else{
			$this->error('修改失败');
		}

	}
}































 ?>